<template>
  <div class="category">
      <s-header :name='"购物车"' :noback="true" />
    <div class="category-container">
      <div class="category-left">
        <van-sidebar v-model="activeKey">
        <van-sidebar-item :title="index.name" v-for="index in categoryList" :key="index.sort"/>
      </van-sidebar>
      </div>
      <div class="category-right">
        <template v-if="categoryList[activeKey] != undefined">
          <van-grid :column-num="2">
            <van-grid-item v-for="value in categoryList[activeKey].children" :key="value.id" icon="photo-o" :text="value.name" :to="'/product-list?categoryId=' + value.id" />
          </van-grid>
          
        </template>
      </div>
    </div>
    <nav-bar></nav-bar>
  </div>
</template>

<script>

import { getCategoryList } from '@/api/category'
import NavBar from '@/components/NavBar.vue'
import SHeader from '../../components/SHeader.vue'

export default {
  components: { NavBar,SHeader },
  name: 'CategoryView',
  data(){
    return {
      activeKey: 0,
      categoryList: [],
    }
  },
  created() {
    this.onLoad()
  },
  methods: {
    async onLoad(){
      await getCategoryList().then(res => {
        if(res.code === 200) {
          this.categoryList = res.data;
        }
      })
    },
  }
}
</script>

<style lang="scss" scoped>

  .category {
    height: 95vh;
    .search {
      padding: 8px 18px 41px 22px;
      background-color: #fff;
    }
    .category-container {
      display: flex;
      // height: 92%;
      width: 100%;
      overflow: auto;
      margin-top: 1px;
      padding-bottom: 50px;
      .category-left {
        height: 700px;
        background-color: #f7f8fa;
      }
      .category-right {
        flex: 1;
        height: 100%;
        .banner {
          padding: 20px 20px 0 20px;
          img {
            width: 546px;
            height: 217.85px;
          }
        }
        .title {
          position: relative;
          margin: 73.15px auto 0;
          width: 120px;
          height: 42px;
          font-family: PingFangSC-Medium;
          font-size: 30px;
          color: #333333;
          letter-spacing: 0;
          font-weight: 500;
          text-align: center;
          &::after {
            position: absolute;
            bottom: 0;
            left: 0;
            z-index: -1;
            content: "";
            width: 100%;
            height: 16px;
            background-color: #b7a673;
          }
        }
        .sub-list {
          display: grid;
          grid-template-columns: repeat(3, 1fr);
          gap: 28.5px 40.01px;
          margin-top: 28.5px;
          padding: 0 48px;
          .item {
            width: 140px;
            img {
              width: 100%;
              height: 140px;
            }
            .name {
              font-family: PingFangSC-Medium;
              font-size: 24px;
              color: #333333;
              letter-spacing: 0;
              font-weight: 500;
              text-align: center;
            }
          }
        }
      }
    }
  }
</style>